package org.fhkoeln.sgdm.sudoku.gui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JFrame;

import org.fhkoeln.sgdm.sudoku.logic.SudokuField;


public class MainFrame extends JFrame implements KeyListener
{
	private static final long serialVersionUID = 1L;
	
	SudokuPanel sPanel = null;
	ButtonPanel bPanel = null;
	
	public static MainFrame instance = null;
	
	public MainFrame()
	{
		super("Sudoku - Backtracking");
		
		instance = this;
		
		this.setSize(new Dimension(450,600));
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		
		this.setLayout(new BorderLayout());

		sPanel = SudokuPanel.getInstance();
		sPanel.setSudokuField(new SudokuField());
		
		this.add(sPanel, BorderLayout.CENTER);
		
		bPanel = new ButtonPanel(this);
		
		this.add(bPanel, BorderLayout.SOUTH);
		
		this.addKeyListener(this);
		sPanel.addKeyListener(this);
		bPanel.addKeyListener(this);
		
		this.setVisible(true);
	}
	
	public void doRepaint()
	{
		sPanel.repaint();
	}

	@Override
	public void keyPressed(KeyEvent e)
	{
		switch(e.getKeyChar())
		{
			case KeyEvent.VK_0:
				sPanel.putDigit(0);
				break;
			case KeyEvent.VK_1:
				sPanel.putDigit(1);
				break;
			case KeyEvent.VK_2:
				sPanel.putDigit(2);
				break;
			case KeyEvent.VK_3:
				sPanel.putDigit(3);
				break;
			case KeyEvent.VK_4:
				sPanel.putDigit(4);
				break;
			case KeyEvent.VK_5:
				sPanel.putDigit(5);
				break;
			case KeyEvent.VK_6:
				sPanel.putDigit(6);
				break;
			case KeyEvent.VK_7:
				sPanel.putDigit(7);
				break;
			case KeyEvent.VK_8:
				sPanel.putDigit(8);
				break;
			case KeyEvent.VK_9:
				sPanel.putDigit(9);
				break;
		}
	}

	@Override
	public void keyReleased(KeyEvent e)
	{
		
	}

	@Override
	public void keyTyped(KeyEvent e)
	{
	}
}
